# -*- coding: utf-8 -*-
import os
import sys
import importlib
sys.path.append(os.path.join(os.path.dirname(__file__), 'tools'))
INSTALL_ROS = 0  # 安装ROS相关
INSTALL_SOFTWARE = 1  # 安装软件
CONFIG_TOOL = 2  # 配置相关

tools_type_map = {
    INSTALL_ROS: "ROS相关",
    INSTALL_SOFTWARE: "常用软件",
    CONFIG_TOOL: "配置工具"
}

tools = {
    1: {'tip': '一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)', 'type': INSTALL_ROS, 'tool': 'tools/tool_install_ros.py', 'dep': [4, 5]},
    3: {'tip': '一键安装:rosdep(小鱼的rosdepc,又快又好用)', 'type': INSTALL_ROS, 'tool': 'tools/tool_config_rosdep.py', 'dep': []},
    13: {'tip': '一键配置:python国内源', 'type': CONFIG_TOOL, 'tool': 'tools/tool_config_python_source.py', 'dep': []},
}

# 创建用于存储不同类型工具的字典
tool_categories = {}

# 遍历tools字典，根据type值进行分类
for tool_id, tool_info in tools.items():
    tool_type = tool_info['type']
    # 如果该类型还没有在字典中创建，则创建一个新的列表来存储该类型的工具
    if tool_type not in tool_categories:
        tool_categories[tool_type] = {}
    # 将工具信息添加到相应类型的列表中
    tool_categories[tool_type][tool_id] = tool_info

def main():
    from tools.base import CmdTask, FileUtils, PrintUtils, ChooseWithCategoriesTask, config_helper
    from tools.base import run_tool_file
    from tools.base import config_helper,tr

    # 直接导入并运行相关模块
    importlib.import_module("tools.translation.translator").Linguist()

    PrintUtils.print_success("已切换到默认语言。")

    # 不再进行语言检测
    PrintUtils.print_success("基础检查通过...")

    code, result = ChooseWithCategoriesTask(tool_categories, tips="-", categories=tools_type_map).run()
    if code == 0:
        PrintUtils().print_success("选择成功。")
    else:
        # 运行所选工具
        run_tool_file(tools[code]['tool'].replace("/", "."))
    config_helper.gen_config_file()

if __name__ == '__main__':
    run_exc = []

    try:
        main()
    except Exception as e:
        import traceback
        print("标题：使用一键安装过程中遇到程序崩溃")
        traceback.print_exc()
        run_exc.append(traceback.format_exc())

    try:
        pass
        # 省略报告逻辑
    except:
        pass
